package cn.shengchao.rule.condition;

import cn.hutool.core.util.StrUtil;
import cn.shengchao.rule.condition.paramKey.IConditionParamKey;
import cn.shengchao.rule.engine.RuleElementContainer;
import lombok.Data;

import java.util.Map;

/**
 * @program: examstarapi
 * @description: 页面入口条件
 * @author: Xiong weiqiang
 * @create: 2025-04-11 16:25
 */
@Data
public class EntryUriCondition extends ICondition{
    // 所有页面
    private static final String ALL_MATCH_VALUE="0";
    @Override
    public IConditionParamKey getParameterKey() {
        return RuleElementContainer.getConditionParamKey(IConditionParamKey.ENTRY_URI);
    }


    @Override
    public boolean isMatch(Map<String,String> targetValueMap) {
       String entryUri=targetValueMap.get(IConditionParamKey.ENTRY_URI);
       if (StrUtil.isBlank(entryUri)){
           return false;
       }
        if (getMatchValue()!=null&&getMatchValue().equals(ALL_MATCH_VALUE)){
            return true;
        }else{
           return super.isMatch(entryUri,getMatchValue());
       }
    }

    @Override
    public int getPriority() {
        return 10;
    }
}